package main;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;

/**
 * 用于生成逆向工程
 *
 */
public class Generator {
    //加载配置文件
    public void mybatisGenerator() throws Exception {
        ArrayList<String> warnings = new ArrayList<>();
        File file = new File("./src/main/resources/generatorConfig.xml");
        ConfigurationParser parser = new ConfigurationParser(warnings);

        Configuration configuration = parser.parseConfiguration(file);
        DefaultShellCallback defaultShellCallback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(configuration, defaultShellCallback, warnings);
        myBatisGenerator.generate(null);



    }
    public static void main(String[] args) throws Exception {
        System.out.println("开始逆向工程");
        Generator generator = new Generator();
        generator.mybatisGenerator();

        System.out.println("结束逆向工程");
    }
}
